<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Design by Free CSS Templates
http://www.freecsstemplates.org
Released for free under a Creative Commons Attribution 2.5 License
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>CSC560 Design and Analysis of Real-Time Systems</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="../default.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="../js/build/fonts/fonts-min.css" />
<link rel="stylesheet" type="text/css" href="../js/build/datatable/assets/skins/sam/datatable.css" />
<script type="text/javascript" src="../js/build/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript" src="../js/build/dragdrop/dragdrop-min.js"></script>
<script type="text/javascript" src="../js/build/element/element-min.js"></script>
<script type="text/javascript" src="../js/build/datasource/datasource-min.js"></script>
<script type="text/javascript" src="../js/build/datatable/datatable-min.js"></script>
<!--begin custom header content for this example-->
<style type="text/css">
/* custom styles for this example */
.yui-skin-sam .yui-dt-liner { white-space:nowrap; } 
</style>
</head>
<body class=" yui-skin-sam">
<div id="wrapper">
	<div id="header">
		<h1>CSC560</h1>
		<h2>Design and Analysis of Real-Time Systems</h2>
		<ul>
			<li class="first">
				<a href="../index.html" accesskey="1" title="">Home</a>
			</li>
			<li>
				<a href="index.html" accesskey="2" title=""><b>Project 1</b></a>
			</li>
			<li>
				<a href="../project2/index.html" accesskey="3" title="">Project 2</a>
			</li>
			<li>
				<a href="../project3/index.html" accesskey="4" title="">Project 3</a>
			</li>
			<li>
				<a href="../project4/index.html" accesskey="4" title="">Project 4</a>
			</li>
			<li>
				<a href="../project5/index.html" accesskey="4" title="">Project 5</a>
			</li>
		</ul>
	</div>
</div>
<div id="content">
	<div id="colOne">
		<h2>Design</h2>
		<p>
			The following section describes the design of the architecture.
			A high-level block diagram is presented, followed by a pin 
			diagram and a entity diagram. 
			A sequence diagram is also presented to understand how communication happens between
			components.
		</p>
		<h2>High-Level Block Diagram</h2>
		<p>
			<a href="../images/blockdiagram.jpg"><img src="../images/blockdiagram.jpg" alt="Block Diagram" align="center" width="100%"/></a>
			
		</p>
		<p>
			The high-level diagram is divided into two sections: the base station and the control station.
			The base station is reponsible for listening to joystick inputs, sending control commands 
			to the control station, and displaying information about the roomba e.g. distance, time and 
			speed.
		</p>
		<p>
			<b>The base station</b><br>
			The base station is composed of an AT90USBKey, a FTDI FT232R USB breakout board,
			and a nRF24L01 radio. The AT90USBKey has a microcontroller that communicates with 
			the USB breakout board through UART (Serial RS232). It also communicates with the radio through
			SPI. The USB breakout board is connected via USB to the pc and sends information 
			to be displayed to a terminal. The nRF24L01 radio controller is used to send packets, e.g. control 
			commands, to the control station radio. The radio has different modes of operation
			that allows it to send and receive packets on a communication link. More details on 
			the radio is explained in the <a href="development_process.html">development process</a> section of the report.
			<br><br>
			
			<b>The control station</b><br>
			The control station is also composed of a nRF24L01 radio which receives packets 
			to be passed on to the roomba. When a packet is received by the radio, it is passed down
			to the AT90USBKey board. The microcontroller of the AT90USBKey then sends the command 
			to the roomba. Finally, the roomba executes the command and sends a status 
			packet back to the base station in a reverse path similar to the one just mentioned.
		</p>
		
		<h2>Pin Diagram</h2>
		<p>
			The picture below shows the pin diagram between the AT90USBKey, FTDI FT232R USB breakout board,
			and the nRF24L01 radio.
		</p>
		<p>
			<a href="../images/pindiagram.jpg"><img src="../images/pindiagram.jpg" alt="Pin Diagram" align="center" width="100%"/></a>
		</p>
		<p>
			The following picture shows the actual wire implementation on a breadboard.
		</p>	
		<p>
			<a href="../images/project1built.jpg"><img src="../images/project1built.jpg" alt="Built Diagram" align="middle" /></a>
		</p>		
		<p>
			<b><u>Connection between the AT90USBKey and FTDI FT232R USB breakout board</u> </b>
			<br>
			PORTD was used to connect the AT90USBKey and the USB breakout board. The TX pin
			of the AT90USBKey is connected to the RX pin of the FTDI FT232R USB breakout board, 
			and the RX pin of the AT90USBKey is connected to the TX pin of the FTDI FT232R USB 
			breakout board. Both GND of the boards are connected together.
		</p>
		<p>
			The following table describes the pins of the FTDI FT232R USB breakout board.
			<div id="basic"></div>

<script type="text/javascript" src="../js/assets/js/data.js"></script>
<script type="text/javascript">
YAHOO.util.Event.addListener(window, "load", function() {
    YAHOO.example.Basic = function() {
        var myColumnDefs = [
            {key:"id", sortable:true, resizeable:true},
            {key:"date", formatter:YAHOO.widget.DataTable.formatDate, sortable:true, sortOptions:{defaultDir:YAHOO.widget.DataTable.CLASS_DESC},resizeable:true},
            {key:"quantity", formatter:YAHOO.widget.DataTable.formatNumber, sortable:true, resizeable:true},
            {key:"amount", formatter:YAHOO.widget.DataTable.formatCurrency, sortable:true, resizeable:true},
            {key:"title", sortable:true, resizeable:true}
        ];

        var myDataSource = new YAHOO.util.DataSource(YAHOO.example.Data.bookorders);
        myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
        myDataSource.responseSchema = {
            fields: ["id","date","quantity","amount","title"]
        };

        var myDataTable = new YAHOO.widget.DataTable("basic",
                myColumnDefs, myDataSource, {caption:"DataTable Caption"});
                
        return {
            oDS: myDataSource,
            oDT: myDataTable
        };
    }();
});
</script>
			
			<table border="1">
				<tr>
			    <th colspan="2" align='center'>FTDI FT232R USB breakout board</th>
			  </tr>
			  <tr>
			    <th align='center'>Pin</th>
			    <th align='center'>Description</th>
			  </tr>
			  <tr>
			    <td>TX</td>
			    <td>Transmit Asynchronous Data Output, type is output</td>
			  </tr>
			  <tr>
			    <td>RX</td>
			    <td>Receive Asynchronous Data Input, type is input</td>
			  </tr>
			  <tr>
			    <td>GND</td>
			    <td>Ground</td>
			  </tr>
			</table>
		</p>
		<p>	
			<b><u>Connection between the AT90USBKey and the nRF24L01 radio</u></b>
			<br>
			The VCC pin of the radio is connected to VCC of the AT90USBKey. The radio can handle
			between 3.3 to 7 Vdc. The CE pin of the radio is conneted to PORTB PB4 of the AT90USBKey.
			This pin has different meanings depending on the mode the radio is operating. The CSN pin 
			is connected to PE6 of the AT90USBKey. This is the enable pin for the SPI bus, and it is
			active low. When sending SPI commands or getting data on the SPI bus, the pin is low.
			The SCK is the serial clock for the SPI bus and it is connected to the SCLK of the 
			AT90USBKey. The way it works is that the clock samples data in the middle of data bits.
			The MOSI pin of the radio is connected to the MOSI pin of AT90USBKey. It stands for
			master out slave in, and this is pin is where the master (AT90USB1287 microcontroller) sends
			data to the slave (radio). The MISO pin acts similarlary to the MOSI except that it
			sends data to the master (AT90USB1287 microcontroller). The IRQ pin is connected to PORTE PE7,
			which is an interrupt on the AT90USBKey. FInally, the GND pin is connected to GND on 
			the AT90USBKey.
		</p>	
			
		<p>
			The following table describes the pins of the nRF24L01 radio.
			<table border="1">
				<tr>
			    <th colspan="2" align='center'>nRF24L01 radio</th>
			  </tr>
			  <tr>
			    <th align='center'>Pin</th>
			    <th align='center'>Description</th>
			  </tr>
			  <tr>
			    <td>Vcc</td>
			    <td>Pin connected to the input of a voltage regulator, can handle 3.3 to 7 Vdc</td>
			  </tr>
			  <tr>
			    <td>CE</td>
			    <td>Chip Enable, Activates RX or TX. This pin has different meaning depending what mode
					it is operating in.</td>
			  </tr>
			  <tr>
			    <td>CSN</td>
			    <td>Chip Select Not. It is the enable pin for the SPI bus. It is active low.</td>
			  </tr>
			  <tr>
			    <td>SCK</td>
			    <td>Serial Clock for the SPI bus. </td>
			  </tr>
			  <tr>
			    <td>MOSI</td>
			    <td>Master Out Slave In. This pin is where the master (AT90USBKey) sends data.</td>
			  </tr>
			  <tr>
			    <td>MISO</td>
			    <td>Master In Slave Out. This pin is where the slave sends data to the master.</td>
			  </tr>
			  <tr>
			    <td>IRQ</td>
			    <td>Interrupt pin to signal the microcontroller something important has happenned. </td>
			  </tr>
			  <tr>
			    <td>GND</td>
			    <td>Ground.</td>
			  </tr>
			</table>
		</p>
		<br>
		<h2>Entity Diagram</h2>
		<p>
			In this section, we are describing the high-level architecture of our code. Each component represents
			a ".c" source file in our structure. For detailed information on the source code, please refer to the
			doxygen files or the source code itself.
			<br><br>
			<a href="../images/classdiagram.jpg"><img src="../images/classdiagram.jpg" alt="code diagram" width='100%'/></a>
		</p>
		
		<p>
			The most important file is Commander.c. It contains our main program. For this project, 
			we have decided to use polling to control joystick events. Therefore, the core of our
			program consists of a single loop. At each iteration, the program
			reads the pins of the joystick to see if a button was pressed. When a button is pressed, a command 
			is passed down to the radio.c file which will then talk to spi.c and put the packet to its Tx FIFO queue.
		</p>
		<p>
			Our main program also interacts with Uart.c, for instance, when a button is pressed or 
			when speed has been calculated and is ready for display. The purpose of interacting with Uart.c
			is greatly needed for inserting debugging statements and also to display meaningful results to the computer terminal.
			A call to uart_putchar() is inserted in the main program when we need to display information to the computer terminal.
			Uart_putchar() function puts data into a buffer and then sends the data to the terminal.
		</p>
		<p>
			Commander.c also interacts with timer.c in order to calculate the time it takes for the roomba to execute a command. For example, 
			when upon receiving a status packet from the roomba resulting from a joystick movement, the time is taken using the Timer_Now() 
			function in timer.c. We store this first time sample in a variable start_time. Upon receiving a second status packet from the roomba
			resulting from another joystick movement, the time is once again taken. We store this time sample in a variable called end_time. 
			With a start and end time, it is now possible to calculate the elapsed time between two commands, which is necessary for calculating
			the speed of the roomba.
		</p>
		<h2>Sequence Diagram</h2>
		<p>
			The following diagram shows the order of operations and iteractions between the different components of our system.
			<br>
			<br>
			<a href="../images/sequencediagram.jpg"><img src="../images/sequencediagram.jpg" alt="Sequence diagram" width='100%'/></a>
			<br>
			First, a user presses a button on the joystick to send a movement command. During the loop iteration, the AT90USBKey microcontroller
			polls the joystick pins to know if they have been set low. If so, it asks the radio to send the command across to 
			the control station. The radio then sends a packet containing the command on its wireless link. On the control station side, 
			the radio receives the commands, and forwards it to the AT90USBKey microcontroller which then sends a command to the roomba.
			Then, the roomba sends a status packet back to the AT90USBKey microcontroller. The latter forwards the packet to its radio who 
			sends the packet across the wireless link back to the base station. The base station radio forward the packet back to the AT90USBKey 
			microcontroller who then sends it to the FTDI FT232R USB breakout board to display speed to the user.
		</p>
		
	</div>
	<div id="colTwo">
		<h3>Project Sections</h3>
		<ul>
			<li class="first"><a href="hardware.html">Hardware Description</a></li>
			<li><a href="design.html"><b>Software Design</b></a></li>
			<li><a href="development_process.html">Development Process</a></li>
			<li><a href="../doxygen/html/index.html">Doxygen</a></li>
			<li><a href="tutorial.html">Tutorial</a></li>
			<li><a href="http://code.google.com/p/wireless-roomba">Google Code</a></li>
		</ul>
	</div>
</div>
<div id="footer">
	<p>@ 2009. All Rights Reserved. Design by <a href="http://www.freecsstemplates.org/">Free CSS Templates</a>.</p>
</div>
</body>
</html>
